<?php

namespace App\Http\Service\menus;

use Illuminate\Support\Facades\Auth;
use App\Http\Models\Permissions\Permissions;

class MenusUserService {

    //获取当前菜单
    public function getUserMenus() {
        //超级管理员菜单 
        if (Auth::user()->users_status) {
            return generateTree(Permissions::where('is_menus', 0)->get()->toArray());
        }
        return generateTree(Permissions::whereIn('id', explode(',', Auth::user()->permissions_id))->get()->toArray());
    }

    //获取所有菜单
    public function getAllMenus() {
        return generateTree(Permissions::where('is_menus', 0)->get()->toArray());
    }

    //获取个人菜单
    public function getPersonalMenus() {
        return array_column(Permissions::whereIn('id', explode(',', Auth::user()->permissions_id))->get('urls')->toArray(), 'urls');
    }

}
